﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace project_phoenix.source
{
    public class NonPlayableEntity : Entity
    {
        public NonPlayableEntity(): base()
        {
            //animation = new AnimationManager("testAnim", EntityManager.Game.Content);
            mStats.Damage = 0;
            mStats.Magic = 0;
            mStats.Defense = 0;
        }

        public void Spawn(Vector2 pos)
        {
            isAlive = true;
            position = pos;
        }

        public void SetupDefaultAnimations()
        {
            // add our animations
            animation.AddAnimation(new Animation(3, 100, 100, 3, Animation.animType.Idle, true));
            animation.AddAnimation(new Animation(3, 100, 100, 3, Animation.animType.Walking, false));
            animation.AddAnimation(new Animation(3, 100, 100, 3, Animation.animType.Attacking, false));
            animation.AddAnimation(new Animation(3, 100, 100, 3, Animation.animType.Blocking, false));
            animation.AddAnimation(new Animation(3, 100, 100, 3, Animation.animType.Dead, false));
            animation.AddAnimation(new Animation(3, 100, 100, 3, Animation.animType.Dying, false));
            animation.AddAnimation(new Animation(3, 100, 100, 3, Animation.animType.Hit, false));
            animation.AddAnimation(new Animation(3, 100, 100, 3, Animation.animType.Jumping, false));

            //default animation is the idle
            animation.PlayAnimation(Animation.animType.Idle);
        }

        public void LoadContent()
        {
            // only make this is we dont have an animation set already
            if(animation == null)
                animation = new AnimationManager("sprites\\ryuAnim");
        }

        public override void Draw()
        {
            if (isAlive == false)
                return;


            animation.Draw(position);
        }

        public override void Update(GameTime gameTime)
        {
            if (isAlive == false)
                return;

            Vector2 dir = new Vector2(0, 0);
            if (Facing == EntityFacing.Left)
                dir.X = -1;
            else
                dir.X = 1;


            // If we are attacking we arent necessarily holding the button down
            if(State == EntityState.Idle /* && State != EntityState.Attacking*/)
                animation.PlayAnimation(Animation.animType.Idle);

            // reset to idle
            State = EntityState.Idle;

            // update our animation
            animation.UpdateAnimation(gameTime, dir);
        }

        public void MoveLeft()
        {
            position.X -= moveSpeed.X;
            Facing = EntityFacing.Left;
            State = EntityState.Walking;
            animation.PlayAnimation(Animation.animType.Walking);
        }

        public void MoveRight()
        {
            position.X += moveSpeed.X;
            Facing = EntityFacing.Right;
            State = EntityState.Walking;
            animation.PlayAnimation(Animation.animType.Walking);
        }

        public void MoveUp()
        {
            position.Y -= moveSpeed.Y;
            State = EntityState.Walking;
            animation.PlayAnimation(Animation.animType.Walking);
        }

        public void MoveDown()
        {
            position.Y += moveSpeed.Y;
            State = EntityState.Walking;
            animation.PlayAnimation(Animation.animType.Walking);
        }

        public void Attack()
        {
            animation.PlayAnimation(Animation.animType.Attacking);
        }

        public void StopMove()
        {
            animation.PlayAnimation(Animation.animType.Idle);
        }
    }
}
